<html>
<head><meta charset="utf-8"><title>dynamic dispatch - supporting more receiver types · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html">dynamic dispatch - supporting more receiver types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="164212800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164212800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164212800">(Apr 25 2019 at 21:45)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="119009">@eddyb</span> </p>
<p>So I thought we should talk again about making dynamic dispatch on trait objects more general, supporting receiver types with arbitrary extra fields instead of just newtyped pointers. I'm going to try to summarize the problem as I understand it so far, please correct me if I got anything wrong.</p>
<p>One of the things we need to do during dynamic dispatch is coerce the "fat" receiver, where <code>Self = dyn Trait</code>, to the "thin" version without the vtable, so it can be passed as an argument to the function that we looked up in the vtable. The tricky thing is, we don't know what the type of <code>Self</code> is, and part of doing the coercion and passing the coerced receiver to the function call is that we need to compute the layout of that type. We need the layout so that we can tell llvm the FnType of the function we're calling, and the layout (and abi) of the function's argument; not to mention it would probably be useful to know the layout when implementing the actual coercion. But to compute the layout of a type, we need an actual type to use.</p>
<p>So the question is, what type do we use for <code>Self</code> once we've removed the vtable? This is what we need to talk about. A couple ideas have been thrown around:<br>
- using <code>()</code><br>
- adding a new variant to <code>TyVariants</code>. One thing I was thinking of was a companion to <code>Dynamic</code>, which takes the same arguments (existential predicates and a lifetime), and implements all the same traits, plus <code>Sized</code>. Except it doesn't <em>really</em> implement those traits, because you couldn't actually call any methods or functions on it. <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span><br>
- you mentioned something about using the type parameter from the <code>DispatchFromDyn</code> impl. Feel free to expand on that if you think it's something worth pursuing</p>



<a name="164237661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237661">(Apr 26 2019 at 06:52)</a>:</h4>
<p>so, <code>()</code> is outright incorrect (because the type might have bounds on that) and a new variant of <code>Ty</code> is <em>not</em> necessary</p>



<a name="164237681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237681">(Apr 26 2019 at 06:53)</a>:</h4>
<p>my idea with the <code>DispatchFromDyn</code> impl was that we could "run it in reverse", to get the e.g. <code>Rc&lt;T&gt;</code>, but we keep the <code>T</code> <em>unsubstituted</em></p>



<a name="164237685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237685">(Apr 26 2019 at 06:53)</a>:</h4>
<p>so it's as if we're doing polymorphic compilation w/o monomorphization</p>



<a name="164237689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237689">(Apr 26 2019 at 06:53)</a>:</h4>
<p>alternatively, we could use some of the Chalk infra</p>



<a name="164237690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237690">(Apr 26 2019 at 06:53)</a>:</h4>
<p>"canonicalization"</p>



<a name="164237736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164237736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164237736">(Apr 26 2019 at 06:54)</a>:</h4>
<p>I don't think <code>general</code> is the correct place for this though, but cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="164242875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164242875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164242875">(Apr 26 2019 at 08:35)</a>:</h4>
<p>no matter what you end up doing, I'd appreciate help realizing this not just in the LLVM backend but also in Miri :D</p>



<a name="164242882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164242882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164242882">(Apr 26 2019 at 08:35)</a>:</h4>
<p>getting "by-value" receivers to work was already lots of guesswork, no idea if I did that right</p>



<a name="164242955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164242955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164242955">(Apr 26 2019 at 08:36)</a>:</h4>
<p>it might be simpler than the hack we do right now</p>



<a name="164242971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164242971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164242971">(Apr 26 2019 at 08:36)</a>:</h4>
<p>I just didn't think we could get it to work, because I think we came up with it <em>before</em> <code>DispatchFromDyn</code> was settled</p>



<a name="164243069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243069">(Apr 26 2019 at 08:38)</a>:</h4>
<p>(FWIW, the current thing is at <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/terminator.rs#L409" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/terminator.rs#L409">https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/terminator.rs#L409</a> )</p>



<a name="164243105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243105">(Apr 26 2019 at 08:38)</a>:</h4>
<p><span class="user-mention" data-user-id="125273">@mikeyhew</span> ugh, <code>ty::Param</code> is suboptimal because you could have <code>Foo&lt;T, X&gt;</code> and <code>X</code> could be unmonomorphized or w/e (maybe in miri, or maybe in codegen, in the future)</p>



<a name="164243132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243132">(Apr 26 2019 at 08:39)</a>:</h4>
<p>so we'll probably have to use <code>ty::Bound</code></p>



<a name="164243146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243146">(Apr 26 2019 at 08:39)</a>:</h4>
<p>which is an universal/existential (not sure) bound variable  from Chalk</p>



<a name="164243660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243660">(Apr 26 2019 at 08:47)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> what would using <code>ty::Bound</code> look like?</p>



<a name="164243730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243730">(Apr 26 2019 at 08:48)</a>:</h4>
<p><span class="user-mention" data-user-id="125273">@mikeyhew</span> you substitute the <code>T</code> in the <code>DispatchFromDyn</code> impl with a <code>ty::Bound</code></p>



<a name="164243770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243770">(Apr 26 2019 at 08:49)</a>:</h4>
<p>well, hmpf. we'd need more analyses on the <code>DispatchFromDyn</code> impl to determine what the type should even look like</p>



<a name="164243771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243771">(Apr 26 2019 at 08:49)</a>:</h4>
<p>it's, like,</p>



<a name="164243791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243791">(Apr 26 2019 at 08:49)</a>:</h4>
<p>we have <code>impl&lt;...&gt; DispatchFromDyn&lt;Foo&lt;A, B&gt;&gt; for Foo&lt;X, Y&gt;</code></p>



<a name="164243849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243849">(Apr 26 2019 at 08:50)</a>:</h4>
<p>OK, so let's say we have</p>
<div class="codehilite"><pre><span></span>impl&lt;T: ?Sized, U: ?Sized, A&gt; DispatchFromDyn&lt;Box&lt;U, A&gt;&gt; for Box&lt;T, A&gt;
where
    T: Unsize&lt;U&gt;
{}
</pre></div>



<a name="164243860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243860">(Apr 26 2019 at 08:50)</a>:</h4>
<p>the <code>impl</code> type parameters used in <code>Self</code> (so in <code>Foo&lt;X, Y&gt;</code>), but not in the trait's parameter (<code>Foo&lt;A, B&gt;</code>)</p>



<a name="164243865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243865">(Apr 26 2019 at 08:50)</a>:</h4>
<p>are the ones you need to "instantiate" when you want to dispatch</p>



<a name="164243868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243868">(Apr 26 2019 at 08:50)</a>:</h4>
<p>uhmmm</p>



<a name="164243869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243869">(Apr 26 2019 at 08:50)</a>:</h4>
<p><code>T: ?Sized</code> is wrong</p>



<a name="164243873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243873">(Apr 26 2019 at 08:50)</a>:</h4>
<p>if you allow that today, something is broken somewhere</p>



<a name="164243890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243890">(Apr 26 2019 at 08:51)</a>:</h4>
<p>details</p>



<a name="164243899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243899">(Apr 26 2019 at 08:51)</a>:</h4>
<p>the reason <code>Unsize</code> allows it is <code>Box&lt;dyn Trait+Send&gt;</code> -&gt; <code>Box&lt;dyn Trait&gt;</code> is a coercion</p>



<a name="164243902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243902">(Apr 26 2019 at 08:51)</a>:</h4>
<p>nope!</p>



<a name="164243909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243909">(Apr 26 2019 at 08:51)</a>:</h4>
<p>without the <code>Sized</code> bound on <code>T</code> in the <code>ParamEnv</code>, none of this can ever work!</p>



<a name="164243922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243922">(Apr 26 2019 at 08:51)</a>:</h4>
<p>Ok, you're right</p>



<a name="164243925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164243925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164243925">(Apr 26 2019 at 08:51)</a>:</h4>
<p>a <code>Sized</code> bound "in scope" means <code>*mut T</code> has a known layout without knowing <code>T</code></p>



<a name="164244002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244002">(Apr 26 2019 at 08:52)</a>:</h4>
<p>So anyway, assuming we can figure out that <code>T/U</code> is type that changes...</p>



<a name="164244007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244007">(Apr 26 2019 at 08:52)</a>:</h4>
<p>and I think we can instantiate all the parameters I was talking about (i.e. <code>T</code> in this case) with <code>ty::Bound</code> (talk to <span class="user-mention" data-user-id="116009">@nikomatsakis</span> maybe? not sure how those work, but they could be like type parameters, just simpler)</p>



<a name="164244128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244128">(Apr 26 2019 at 08:54)</a>:</h4>
<p>you don't need to know anything about the <code>U</code>, just be able to find that <code>impl</code> and get a <code>Box&lt;T, MyAlloc&gt;</code> from a <code>Box&lt;Whatever, MyAlloc&gt;</code></p>



<a name="164244243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244243">(Apr 26 2019 at 08:56)</a>:</h4>
<p>I guess by using the trait system and asking for <code>X</code> and <code>Y</code> in <code>Box&lt;X, Y&gt;</code> where <code>Box&lt;X, Y&gt;: DispatchFromDyn&lt;Box&lt;Whatever, MyAlloc&gt;&gt;</code></p>



<a name="164244245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244245">(Apr 26 2019 at 08:56)</a>:</h4>
<p>wait</p>



<a name="164244255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244255">(Apr 26 2019 at 08:56)</a>:</h4>
<p>"replace it with <code>ty::Bound</code>" sounds nice, but I have no idea what that really means - can you elaborate on how to do that? <code>ty::Bound</code> has arguments</p>



<a name="164244259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244259">(Apr 26 2019 at 08:56)</a>:</h4>
<p>ugh, the direction of this might be hard to do trait dispatch with</p>



<a name="164244269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244269">(Apr 26 2019 at 08:56)</a>:</h4>
<p>oh, you'd just use whatever works for those :P</p>



<a name="164244318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244318">(Apr 26 2019 at 08:57)</a>:</h4>
<div class="codehilite"><pre><span></span>/// Bound type variable, used only when preparing a trait query.
    Bound(ty::DebruijnIndex, BoundTy),
</pre></div>



<a name="164244328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244328">(Apr 26 2019 at 08:57)</a>:</h4>
<p>maybe <code>Bound</code> is wrong and I mean <code>Placeholder</code>?</p>



<a name="164244331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244331">(Apr 26 2019 at 08:57)</a>:</h4>
<p>some of this is a bit weird</p>



<a name="164244388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244388">(Apr 26 2019 at 08:58)</a>:</h4>
<div class="codehilite"><pre><span></span>/// A placeholder type - universally quantified higher-ranked type.
    Placeholder(ty::PlaceholderType),
</pre></div>



<a name="164244389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244389">(Apr 26 2019 at 08:58)</a>:</h4>
<p>but you can just use debruijin index 0 and <code>BoundVar</code> index 0</p>



<a name="164244399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244399">(Apr 26 2019 at 08:58)</a>:</h4>
<p>and <code>BoundTyKind::Anon</code></p>



<a name="164244454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244454">(Apr 26 2019 at 08:59)</a>:</h4>
<p>it really doesn't matter, beyond two very important things:</p>
<ul>
<li>have a version of the <code>ParamEnv</code> of the <code>impl</code>, with that special type in the position</li>
<li>be able to grab the layout for the smart pointer, with that special type used in the strategical position, such that it's "obviously a thin pointer"</li>
</ul>



<a name="164244532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164244532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164244532">(Apr 26 2019 at 09:00)</a>:</h4>
<p>(if you need multiple, you can use further <code>BoundVar</code> indices)</p>



<a name="164245078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikeyhew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245078">(Apr 26 2019 at 09:08)</a>:</h4>
<p>Grepping through the rust-lang/rust source, I don't see <code>ty::Bound</code> being used in a way that I can learn from. If there's a solution involving it, I'd love to hear about it, but I'd need someone to explain to me how it works before I can implement anything with it</p>



<a name="164245709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245709">(Apr 26 2019 at 09:17)</a>:</h4>
<p><span class="user-mention" data-user-id="125273">@mikeyhew</span> you just use it like you might use, idk, <code>ty::Err</code></p>



<a name="164245762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245762">(Apr 26 2019 at 09:18)</a>:</h4>
<p>you just put it where the unknown is</p>



<a name="164245787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245787">(Apr 26 2019 at 09:18)</a>:</h4>
<p><span class="user-mention" data-user-id="125273">@mikeyhew</span> I guess a better analogy is an inference variable, but this sort of thing is not restricted from appearing in a global tcx</p>



<a name="164245806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245806">(Apr 26 2019 at 09:19)</a>:</h4>
<p>and it seems reasonable to allow layout to handle it</p>



<a name="164245836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164245836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164245836">(Apr 26 2019 at 09:19)</a>:</h4>
<p>you could use <code>ty::Param</code> directly, from the <code>impl</code>, I'm just worried about bad interactions in the future</p>



<a name="164246003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164246003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164246003">(Apr 26 2019 at 09:22)</a>:</h4>
<p>again, it doesn't matter what you use, but you need something like <code>Rc&lt;StrangeThing&gt;</code>, where if you have <code>StrangeThing: Trait</code> in <code>ParamEnv</code>, the trait system will actually consider that</p>



<a name="164246073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/dynamic%20dispatch%20-%20supporting%20more%20receiver%20types/near/164246073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/dynamic.20dispatch.20-.20supporting.20more.20receiver.20types.html#164246073">(Apr 26 2019 at 09:23)</a>:</h4>
<p>because the <code>impl</code> has a <code>T: Sized</code> bound in its <code>ParamEnv</code> so when you substitute <code>[T -&gt; StrangeThing]</code>, you'll get <code>StrangeThing: Sized</code>, which is important for ensuring <code>*mut RcBox&lt;StrangeThing&gt;</code> is actually a thin pointer</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>